//
//  Global.swift
//  MECollege
//
//  Created by 马康旭 on 2017/7/11.
//  Copyright © 2017年 马康旭. All rights reserved.
//

import UIKit


// MARK:- 屏幕尺寸获取(屏幕适配)
let screenBounds = UIScreen.main.bounds.size
let screenWidth = screenBounds.width
let screenHeight = screenBounds.height


/// 基于iPhone6垂直方向适配
///
/// - Parameter size: iPhone6垂直方向尺寸
/// - Returns: 其他型号尺寸
func layoutVertical(iPhone6: CGFloat) -> CGFloat {
    
    var newHeight: CGFloat = 0
    
    switch iPhoneModel.currentModel {
    case .iPhone5:
        newHeight = iPhone6 * (568.0 / 667.0)
    case .iPhone6:
        newHeight = iPhone6
    case .iPhone6p:
        newHeight = iPhone6 * (736.0 / 667.0)
    default:
        newHeight = iPhone6 * (1024.0 / 667.0 * 0.9)
    }
    
    return newHeight
    
}

/// 基于iPhone6水平方向适配
///
/// - Parameter iPhone6: iPhone6水平方向尺寸
/// - Returns: 其他型号尺寸
func layoutHorizontal(iPhone6: CGFloat) -> CGFloat {
    
    var newWidth: CGFloat = 0
    
    switch iPhoneModel.currentModel {
    case .iPhone5:
        newWidth = iPhone6 * (320.0 / 375.0)
    case .iPhone6:
        newWidth = iPhone6
    case .iPhone6p:
        newWidth = iPhone6 * (414.0 / 375.0)
    default:
        newWidth = iPhone6 * (768.0 / 375.0 * 0.9)
    }
    
    return newWidth
    
}

/// 基于iPhone6字体的屏幕适配
///
/// - Parameter iPhone6: iPhone字体大小
/// - Returns: 其他型号字体
func layoutFont(iPhone6: CGFloat) -> CGFloat {
    
    var newFont: CGFloat = 0
    
    switch iPhoneModel.currentModel {
    case .iPhone5:
        newFont = iPhone6 * (320.0 / 375.0)
    case .iPhone6:
        newFont = iPhone6
    case .iPhone6p:
        newFont = iPhone6 * (414.0 / 375.0)
    default:
        newFont = iPhone6 * 1.2
    }
    
    return newFont
}

/**
 手机型号枚举
 */
enum iPhoneModel {
    
    case iPhone4
    case iPhone5
    case iPhone6
    case iPhone6p
    case iPad
    
    /**
     获取当前设备型号
     
     - returns: 返回手机型号枚举
     */
    static var currentModel: iPhoneModel {
        
        get{
            switch screenHeight {
            case 480:
                return .iPhone4
            case 568:
                return .iPhone5
            case 667:
                return .iPhone6
            case 736:
                return .iPhone6p
            default:
                return .iPad
            }
        }
    }
}



// MARK:- 自定义打印
func MELog<T>(_ message: T,
           file: String = #file,
           method: String = #function,
           line: Int = #line)
{
    #if DEBUG
        print("\((file as NSString).lastPathComponent)[\(line)], \(method): \(message)")
    #endif 
}


//MARK:- 拼接腾讯直播SDK返回的错误信息
func MEAppendMessage(title: String, components: String? ...) -> String{
    
    var message = ""
    
    message += title
    message += ":--"
    
    for component in components{
        
        if let string = component{
            message += string
            message += "--"
        }
    }
    
    return message
}

struct Platform {
    static let isSimulator: Bool = {
        var isSim = false
        #if arch(i386) || arch(x86_64)
            isSim = true
        #endif
        return isSim
    }()
}
